﻿
//--> Loth 2011 
//--> Complete Interface v0.3

package  chamans{
	import flash.display.*;
	import flash.geom.*;
	import flash.utils.*;
	
	public class Tool{
		public function Tool ():void
		{
		}
		public function bit(Clip:*, w:int=0, h:int=0, z:Number=1, t:Boolean=false, R:int=0, F:Boolean=false, high:Boolean=true,c:int=0x000000):BitmapData
		{
			if(w==0 && h==0) { w=Clip.width; h=Clip.height; }
			var B:BitmapData=new BitmapData(w*z, h*z, t, c)
			var  M:Matrix=new Matrix();
			if (R!=0){ M.translate(-w/2,-h/2); M.rotate( R * (Math.PI / 180 )); M.translate(w/2,h/2); }
			if (F){M.scale( z, -z ) ; M.translate(0,h*z);}
			else  M.scale( z, z );
			B.draw( Clip, M );
			return B;
		}
		public function color( o:*, c:int=0, a:Number=1 ):void
		{
			var nc:ColorTransform = o.transform.colorTransform
			nc.color = c; nc.	alphaMultiplier = a; 
			if(c==0)o.transform.colorTransform = new ColorTransform()
			else o.transform.colorTransform = nc
		}
		public function Ran(max:Number=1, min:Number=0):Number 
		{
			return Math.floor(Math.random() * (max - min + 1)) + min;
			//return Number(((max-min+1)*Math.random()+min).toFixed(f));
		}
		public function map_BG (g:Shape,img:BitmapData, sw:int=10, sh:int=10, x:int=-550, y:int=-400):void
		{
			var mat:Matrix = new Matrix();  
			mat.translate(x,y);
			drawbg(g, img, mat, sw, sh, -sw>>1, -sh>>1, 0x101010, 1)
		}
		public function drawbg(g:Shape, img:BitmapData, M:Matrix , w:int=1, h:int=1, x:int=0, y:int=0, c:int=0x00, a:Number=1):Shape {
			g.graphics.clear()
			g.graphics.beginBitmapFill( img, M , true, false);
			g.graphics.drawRect(x,y,w,h);
			g.graphics.endFill()
			return g  }
		public function drawbg2(g:Shape, w:int=1, h:int=1, x:int=0, y:int=0, c:int=0x00, a:Number=1):Shape {
			g.graphics.clear();
			g.graphics.beginFill(c, a);
			g.graphics.drawRect(x,y,w,h);
			g.graphics.endFill()
			return g;  }
		public function Box(o:*, c:int=0x000000, w:int=12, h:int=12, d:int=4,  a:Number=1):void {
			
			o.graphics.clear()
			o.graphics.beginFill(c, a);
			o.graphics.moveTo (d,0)      
			o.graphics.lineTo (w+d, 0)
			o.graphics.lineTo (w-d, h)
			o.graphics.lineTo (-d, h)	 
			o.graphics.endFill();
		}
		public function Box2(o:*, color:int=0x000000,  x:int=12, y:int=12, w:int=12, h:int=12):void {
			
			o.graphics.clear();
			o.graphics.lineStyle(0,color,1);
			o.graphics.moveTo (x,y)      
			o.graphics.lineTo (w+x, y)
			o.graphics.lineTo (w+x, h+y)
			o.graphics.lineTo (x,h+y)	 
			o.graphics.endFill();
		}
		public function BGstripe( c:int=0x383838, c2:int=0x353535, w:int=64, a:Number=1):Shape {
			var o:Shape=new Shape()
			o.graphics.beginFill(c2, a); o.graphics.moveTo (0,0);  o.graphics.lineTo (w, 0); o.graphics.lineTo (0, w);
			o.graphics.beginFill(c, a); o.graphics.moveTo (0,0); o.graphics.lineTo (w>>1, 0); o.graphics.lineTo (0, w>>1);
			o.graphics.beginFill(c,a); o.graphics.moveTo (w,w); o.graphics.lineTo (w, 0); o.graphics.lineTo (0, w);
			o.graphics.beginFill(c2, a); o.graphics.moveTo (w,w); o.graphics.lineTo (w>>1, w); o.graphics.lineTo (w, w>>1);
			o.graphics.endFill();
			return o;
		}
		public function Disclight( c:int, a:Number=1, w:int=100, h:int=100, x:int=0, y:int=0, t:Boolean=false, l:int=0):Shape
		{
			var g:Shape=new Shape
			var mtx:Matrix = new Matrix();
			mtx.createGradientBox(w,h,0,0,0);
			g.graphics.beginGradientFill(GradientType.RADIAL, [c,c, c], [1,.25,0], [0,60,255], mtx);
			g.graphics.drawEllipse(x,y,w,h)
			g.graphics.endFill()
			return g
		}
		public function CARRE( u:Object=null ):Shape {
			var G:Object={ color:u.color || 0x000000, alpha:u.alpha || 1,
				lcolor:u.lcolor || 0x000000, lalpha:u.lalpha || 1,
				w:u.w || 10, h:u.h || 10,
				x:u.x || 0, y:u.y || 0,
				r:u.r || 0, // arrondi
				line:u.line || false,
				g:u.obj || new Shape()
			}
			if(u.alpha==0)G.alpha=0
			with(G){
				if(line)g.graphics.lineStyle(0, lcolor, lalpha);
				g.graphics.beginFill(color, alpha);
				if(r!=0) g.graphics.drawRoundRect(x,y,w,h,r,r);
				else g.graphics.drawRect(x,y,w,h);
				return g;
			}}
		
		public function Orbit( H:Number=-25, V:Number=90, D:int=20000 ):Vector3D 
		{
			var P:Vector3D=new Vector3D();
			var phi:Number= RadDeg(H);
			var theta:Number= RadDeg(V);
			P.x = (D * Math.sin(phi)*Math.cos(theta));
			P.z = (D * Math.sin(phi)*Math.sin(theta));
			P.y = (D * Math.cos(phi));
			return P;
		}
		public function RadDeg(d:Number):Number{ return(d * (Math.PI / 180)) }
		// end
	}}